/* Copyright - Apache License 2.0
 * 
 * The project "kyou" is
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *      http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.kyou.pack.segment;

import java.nio.charset.Charset;

import net.kyou.exception.KyouErr;
import net.kyou.exception.KyouException;
import net.kyou.pack.UTILS;

import org.junit.Assert;
import org.junit.Test;

public class SegmentTest {

    @Test
    public void test() {
        try {
            String xml = "<text>aaa</text>";

            Segment segment = Segment.__new(UTILS.prepareElement(xml), Charset.forName("utf-8"), null);

            Assert.assertTrue(segment instanceof TextSegment);
        } finally {
        }
    }

    @Test
    public void testEx() {
        try {
            String xml = "<xxx>aaa</xxx>";

            Segment.__new(UTILS.prepareElement(xml), Charset.forName("utf-8"), null);

            Assert.fail();
        } catch (KyouException ex) {
            Assert.assertEquals(KyouErr.Style.InitSegmentFail, ex.err);
            Assert.assertEquals(KyouErr.Style.InvalidSegmentTag, ((KyouException) ex.cause).err);
        }

        try {
            String xml = "<str>aaa</str>";

            Segment.__new(UTILS.prepareElement(xml), Charset.forName("utf-8"), null);

            Assert.fail();
        } catch (KyouException ex) {
            Assert.assertEquals(KyouErr.Style.InitSegmentFail, ex.err);
            Assert.assertEquals(KyouErr.Style.InitParamFail, ((KyouException) ex.cause).err);
        }
    }
}
